{% load static %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{{ title|default:"操作成功" }}</title>
  <link href="{% static 'vendor/bootstrap/bootstrap.min.css' %}" rel="stylesheet">
  <link href="{% static 'vendor/fontawesome/all.min.css' %}" rel="stylesheet">
  <style>
    body { padding: 16px; }
  </style>
</head>
<body>
  <div class="container-fluid">
    <div class="alert alert-success d-flex align-items-center" role="alert">
      <i class="fas fa-check-circle me-2"></i>
      <div>{{ message|default:"操作已成功完成。您可以关闭窗口，或点击下方按钮刷新列表页。" }}</div>
    </div>
    <div class="d-flex gap-2">
      <button class="btn btn-primary" onclick="notifyParentSuccess()"><i class="fas fa-sync-alt me-1"></i>完成并刷新</button>
      <button class="btn btn-outline-secondary" onclick="closeModal()">关闭</button>
    </div>
  </div>
  <script>
    function notifyParentSuccess(){
      try {
        const msg = { type: 'asset:operation-success', message: (document.querySelector('.alert-success div')?.innerText || '操作成功') };
        window.top?.postMessage(msg, '*');
      } catch(e) { /* no-op */ }
      // 退一步：无法与父页面通信时，直接刷新自身或回退
      try { if (window.top === window) { window.location.href = '/assets/'; } } catch(e) {}
    }
    function closeModal(){ try { window.top.document.querySelector('#actionIframeModal .btn-close')?.click(); } catch(e) { window.history.back(); } }
    // 自动聚焦刷新按钮，回车可刷新
    try { document.querySelector('.btn.btn-primary')?.focus(); } catch(e) {}
  </script>
</body>
</html>
